package com.webonn.frame.util;

import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/22.
 */
public class APIResultBuilder {
    //成功
    public static <T> Response OK(T data){
        return Response.status(200).entity(data).build();
    }
    //已建立
    public static <T> Response CREATED(T data){
        return Response.status(201).entity(data).build();
    }
    //已接受
    public static <T> Response Accepted(T data){
        return Response.status(202).entity(data).build();
    }
    //无内容
    public static <T> Response NO_CONTENT(T data){
        return Response.status(204).entity(data).build();
    }
    //客户端错误，无效的请求
    public static Response INVALID_REQUEST(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(400).entity(doc).build();
    }
    //客户端错误，未认证
    public static Response Unauthorized(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(401).entity(doc).build();
    }
    //客户端错误，禁止
    public static Response Forbidden(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(403).entity(doc).build();
    }
    //客户端错误，没有找到
    public static Response NOT_FOUND(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(404).entity(doc).build();
    }
    //客户端错误，离开
    public static Response Gone(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(410).entity(doc).build();
    }
    //客户端错误，无法处理的请求实体
    public static Response UnprocesableEntity(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(422).entity(doc).build();
    }
    //服务器错误，内部错误
    public static Response INTERNAL_SERVER_ERROR(String error){
        Map<String, Object> doc = new HashMap<>();
        doc.put("error", error);
        return Response.status(500).entity(doc).build();
    }
}
